package com.lili.deptservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lili.deptservice.entity.TbDepartment;
import com.lili.deptservice.service.TbDepartmentService;
import com.lili.utilscommon.response.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ange
 * @since 2020-07-27
 */
@CrossOrigin
@RestController
@RequestMapping("/aa/tb-department")

public class TbDepartmentController {

    @Autowired
    private TbDepartmentService tbDepartmentService;

    @ApiOperation(value = "查询所有部门信息")
    @GetMapping("/findDeptList")
    public Result findDeptList(){
        QueryWrapper<TbDepartment> queryWrapper = new QueryWrapper<>();
        //queryWrapper.select("name");
        List<TbDepartment> departmentList = tbDepartmentService.list(queryWrapper);
        return Result.ok().data("departmentList",departmentList);
    }

    @ApiOperation(value = "分组查询部门信息并统计部门人数")
    @GetMapping("/findDeptAndCount")
    public Result findDeptAndCount(){
        List<TbDepartment> deptAndCount = tbDepartmentService.findDeptAndCount();
        return Result.ok().data("deptAndCount",deptAndCount);
    }
}

